package bdd;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.ArrayList;

public class BddPreparedStatement {
	public static PreparedStatement getPrepareStatement(String query) throws Exception {
		
		return BddPreparedStatement.getPrepareStatement(query, true);
		
	}
	
	public static PreparedStatement getPrepareStatement(String query, boolean autoCommit) throws Exception {
		
		Connection connection = BddConnection.getInstance();
		
		connection.setAutoCommit(autoCommit);
		
		return connection.prepareStatement(query);
	}
	
	@SuppressWarnings("unchecked")
	public static ArrayList paginer(ArrayList liste, int debut, int nb) {
		ArrayList listeRetour = new ArrayList();
		
		int max = debut + nb;
		if (liste.size() < max)
			max = liste.size();
		
		for (int i = debut; i < max; i++)
			listeRetour.add(liste.get(i));
		
		return listeRetour;
	}
}
